package com.liang.jiekou.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.liang.jiekou.entity.*;
import com.liang.jiekou.entity.dto.LldDto;
import com.liang.jiekou.entity.dto.LldList;
import com.liang.jiekou.mapper.*;
import com.liang.jiekou.service.MOCTCService;
import com.liang.jiekou.untils.HttpClientUtil;
import com.liang.jiekou.untils.RunHttp;
import com.liang.jiekou.untils.TimeUtils;
import com.sun.java.swing.plaf.motif.MotifDesktopIconUI;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

//import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;
@Slf4j
@Service
public class MOCTCServiceImpl implements MOCTCService {
    @Resource
    private ADMMFMapper admmfMapper;

    @Resource
    private CMSMDMapper cmsmdMapper;

    @Resource
    private MOCTAMapper moctaMapper;

    @Resource
    private MOCTBMapper moctbMapper;

    @Resource
    private MOCTCMapper moctcMapper;

    @Resource
    private MOCTEMapper mocteMapper;

    @Resource
    private CMSMQMapper cmsmqMapper;

    @Resource
    private INVMBMapper invmbMapper;

    @Resource
    private INVMLMapper invmlMapper;

    @Resource
    private INVMCMapper invmcMapper;

    @Resource
    private MoctdMapper moctdMapper;


    @Override
    public Result add(LldDto lldDto) {

        int flage = 0;
        String xxx = "";

        // 领料单创建人
        String creator = lldDto.getCreator();
        // 领料日期
        String rq = lldDto.getRq();
        // 工厂编号
        String gcbh = lldDto.getGcbh();
        //  工作中心
        String gzzx = lldDto.getGzzx();
        //  领料单单别
        String lld = lldDto.getDb();
        // 领料工单列表
        List<LldList> list = lldDto.getList();

        // 1.判断领料单是否合规

        // 2.判断工单是否合规
        String errorMsg =  null ;
        for (LldList lllist : list) {

            String db = lllist.getGddb();
            String dh = lllist.getGddh();
            /*QueryWrapper<Cmsmq> cmsmqQueryWrapper = new QueryWrapper<>();
            cmsmqQueryWrapper.eq("MQ001",db);
            CMSMQ cmsmq = cmsmqMapper.selectOne(cmsmqQueryWrapper);*/
            CMSMQ cmsmq = cmsmqMapper.findByMQ001(db);
            //String mq001 = cmsmqMapper.isExitByMQ001(db);
            //if (mq001 == null || )
            //System.out.println("mq001::" + mq001);
            if (!(db.substring(0,2).equals("51")||db.substring(0,2).equals("52"))||cmsmq==null)
            {
                //log.info(cmsmqMapper.isExitByMQ001(db));

                System.out.println("---工单单别为：" + db);
                if (errorMsg != null)
                    errorMsg  += "\n" + db +" : 这个工单单别有误！";
                else
                    errorMsg  =  db +" : 这个工单单别有误！";
                flage = 1;
                continue;
            }
            if (errorMsg != null && flage ==1) continue;

            // 获取工单信息
            /*QueryWrapper<Mocta> moctaQueryWrapper = new QueryWrapper<>();
            moctaQueryWrapper.eq("TA001",db)
                    .eq("TA002",dh);

            MOCTA mocta = moctaMapper.selectOne(moctaQueryWrapper);*/
            MOCTA mocta = moctaMapper.findByDbWithDh(db,dh);

            if (mocta==null){
                if (errorMsg != null)
                    errorMsg  += "\n" + dh +" : 这个工单单号不存在！";
                else
                    errorMsg  =  dh +" :  这个工单单号不存在！";
                flage = 2;
                continue;
            }
            if (errorMsg != null && flage==2) continue;
            // 判断工单是否被审核
            if (!mocta.getTA013().equals("Y")){
                if (errorMsg != null)
                    errorMsg  += "\n" + dh +" : 这个工单单号没有审核！";
                else
                    errorMsg  =  dh +" :  这个工单单号没有审核！";
                continue;
            }

            //log.info(mocta.toString());
        }
        System.out.println("123");
        if (errorMsg != null) {
            System.out.println(errorMsg);
            /*Result result = new Result();
            result.setMsg(errorMsg);
            result.setCode("404");
            return result;*/
            return Result.error(errorMsg);
        }

        // 3.领料单单身信息创建
        MOCTC moctc = new MOCTC();
        String nowTime = TimeUtils.getNowTime();
        // 设置创建者
        moctc.setCOMPANY("ttc");
        moctc.setCREATOR(creator);

        // ADMMF admmf = admmfMapper.selectOne(new QueryWrapper<Admmf>().eq("MF001", creator));
        ADMMF admmf = admmfMapper.selectByMF001(creator);

        System.out.println("admmf:" + admmf.toString());
        moctc.setUSR_GROUP(admmf.getMF004());
        moctc.setCREATE_DATE(nowTime);
        moctc.setMODI_DATE("");
        moctc.setMODIFIER("");
        moctc.setFLAG(new BigDecimal(2));

        // 获取领料单单别 对应的信息
        //CMSMQ cmsmq = cmsmqMapper.selectOne(new QueryWrapper<Cmsmq>().eq("MQ001",lld));
        CMSMQ cmsmq = cmsmqMapper.findByMQ001(lld);

        // 领料单对应的年位数
        int yearLength = cmsmq.getMQ005().intValue();
        // 获取根据单别获取单号
        String tc002 = null;
        if (yearLength == 4) tc002 = moctcMapper.getNewTC002Year4(lld);
        else tc002 = moctcMapper.getNewTC002Year2(lld);

        moctc.setTC001(lld);
        moctc.setTC002(tc002);
        moctc.setTC003(rq);
        moctc.setTC004(gcbh);
        moctc.setTC005(gzzx);
        moctc.setTC006("");
        moctc.setTC007("");
        moctc.setTC008(lld.substring(0,2));
        // 设置审核码
        moctc.setTC009("N");
        // 设置打印次数
        moctc.setTC010(new BigDecimal(0));
        // 设置生成分录-成本  Y/N
        moctc.setTC011("N");
        // 设置 生成排序 1.按工单单号、2.按材料品号
        moctc.setTC012("1");
        // 取数方式 Y.需领用量、N.与库存量比较
        moctc.setTC013("Y");
        // 设置  单据日期 过来的
        moctc.setTC014(rq);
        // 设置审核者
        moctc.setTC015("");
        // 签核状态码 0.待处理、S.传送中、1.签核中、2.退件、3.已核准、4.撤销审核中、5.作废中、
        // 6.取消作废中、N.不运行电子签核[DEF:"N"]
        moctc.setTC016("N");
        // 设置 传送次数
        moctc.setTC017(new BigDecimal(0));
        //   来源别 0.自行输入、1.工单、2.生产入库自动扣料、3.委外进自动扣料、4.委外退自动扣料、
        // 5.开工单、6.委外进厂供料自动扣料、7.委外退厂供料自动扣料 8.批次发料自动退料[DEF:"0"]
        moctc.setTC018("0");
        // 设置   来源单别
        //moctc.setTC019(db);
        // 设置 来源单号
        //moctc.setTC020(dh);
        //moctcMapper.add(moctc);
        // 设置 部门
        // 根据工作中心编号获取 工作中心
        //CMSMD cmsmd = cmsmdMapper.selectOne(new QueryWrapper<Cmsmd>().eq("MD001",gzzx));
        CMSMD cmsmd = cmsmdMapper.getCMSMDByMD001(gzzx);
        moctc.setTC021(cmsmd.getMD015().trim());
        // 设置人员编号
        moctc.setTC028("");
        moctc.setTC031("");
        log.info("moctc :" + moctc.toString());

        //添加领料单单身

        List<MOCTE> moctes = new ArrayList<>();

        List<Moctd> moctds = new ArrayList<>();
        int xh = 1;
        double count = 0;
        for (LldList lllist : list) {
            boolean flag = false;
            Moctd moctd = new Moctd();
            if (!xxx.equals(lllist.getGddh() + lllist.getGddh())) {
                moctd.setCompany("ttc");
                moctd.setCreator(creator);
                moctd.setUsrGroup(admmf.getMF004());
                moctd.setCreateDate(nowTime);
                moctd.setTd001(lld);
                moctd.setTd002(tc002);
                moctd.setTd003(lllist.getGddb());
                moctd.setTd004(lllist.getGddh());
                MOCTA mocta = moctaMapper.selectOne(new QueryWrapper<MOCTA>()
                        .eq("TA001", lllist.getGddb())
                        .eq("TA002", lllist.getGddh()));
                moctd.setTd005(lllist.getLlfs());
                moctd.setTd006(lllist.getTs());
                moctd.setTd007(mocta.getTA021());
                moctd.setTd008(lllist.getLlCode());
                moctd.setTd015("1");
                moctd.setTd017("1");
                moctd.setTd019(lllist.getLlts());
                moctd.setTdc01("2");
                flag = true;
            }
            xxx = lllist.getGddh() + lllist.getGddh();
            // 判断该物料是否领取完成

            //   判断是否存在该物料
            /*MOCTB moctb = moctbMapper.selectOne(new QueryWrapper<Moctb>().eq("TB001", lllist.getGddb())
                    .eq("TB002", lllist.getGddh()).
                    eq("TB003", lllist.getWlbh()));*/
            MOCTB moctb = moctbMapper.getMOCTBBYTB001andTB002andTB003(lllist.getGddb(), lllist.getGddh(),lllist.getWlbh());
            if (moctb == null) {
                if (errorMsg == null )
                    errorMsg = "工单单别为: " + lllist.getGddb() +"，  工单单号为"+ lllist.getGddh() + "的工单中, 没有物料编号为：" + lllist.getWlbh() +  "物料信息";
                else errorMsg = "\n" + errorMsg;

                continue;
            }

            // 存在查看库存数量和要领的数量 需要获取工单单身每个物料的仓库
            //物料对应的仓库编号
            String tb009 = moctb.getTB009();
            /*QueryWrapper<Invmc> invmcQueryWrapper = new QueryWrapper<>();
            invmcQueryWrapper.eq("MC001",lllist.getWlbh()).eq("MC002",tb009);
            INVMC invmc = invmcMapper.selectOne(invmcQueryWrapper);*/
            INVMC invmc = invmcMapper.getINVMCByMC001WithMC002(lllist.getWlbh(),tb009);
            if (invmc==null){
                errorMsg += "/n工单单别为: " + lllist.getGddb() +"，  工单单号为"+ lllist.getGddh() + "的工单中, 仓库编号："+tb009+"中没有对应的物料编号为：" + lllist.getWlbh() +  "的信息";
                continue;
            }
            // 获取库存数量
            Double mc007 = invmc.getMC007().doubleValue();
            if (mc007 < lllist.getQtw()){
                if (errorMsg != null)
                    errorMsg  +=
                            "/n" + "工单单别为 ：" + lllist.getGddb() + "，单号为：" + lllist.getGddh() + "，中的需要领料的单号为：" + lllist.getWlbh() +"，的产品在仓库中的数量不足!" ;
                else
                    errorMsg  =
                            "工单单别为 ：" + lllist.getGddb() + "，单号为：" + lllist.getGddh() + "，中的需要领料的单号为：" + lllist.getWlbh() +"，的产品在仓库中的数量不足!" ;

                log.info(errorMsg);
                flage = 3;
                continue;
            }

            // errorMsg 不为空说明 存在库问题 不用在列表中添加
            if (errorMsg != null && flage == 3)
                continue;

            // 仓库库存满足  设置领料单单身
            count += lllist.getQtw();
            MOCTE mocte = new MOCTE();
            mocte.setCOMPANY(moctb.getCOMPANY().trim());
            mocte.setCOMPANY(creator);
            mocte.setUSR_GROUP(admmf.getMF004());
            mocte.setCREATE_DATE(nowTime);
            mocte.setFLAG(new BigDecimal(2));
            mocte.setTE001(lld);
            mocte.setTE002(tc002);
            mocte.setTE003(String.format("%04d", xh));
            xh++;
            // 物料品号
            mocte.setTE004(lllist.getWlbh());
            // 领料数量
            mocte.setTE005(new BigDecimal(lllist.getQtw()));
            // 单位
            mocte.setTE006(moctb.getTB007().trim());
            // 参考单位
            mocte.setTE007("");
            // 仓库
            mocte.setTE008(tb009);
            // 工艺
            mocte.setTE009("****");
            //批号
            mocte.setTE010("********************");
            // 工单单别 单号
            mocte.setTE011(lllist.getGddb());
            mocte.setTE012(lllist.getGddh());
            // 设置领料说明
            mocte.setTE013("可用量: " + Math.round(mc007));
            // 备注
            mocte.setTE014("");
            mocte.setTE015("");
            // 材料类型
            mocte.setTE016(moctb.getTB011());

            mocte.setTE017(moctb.getTB012().trim());
            // 设置材料规格
            mocte.setTE018(moctb.getTB013().trim());
            // 设置审核码
            mocte.setTE019("N");
            // 设置项目编号
            //mocte.setTE020(moctb.getTB038().trim());
            //mocte.setTE020("********************");
            mocte.setTE020("");
            // 设置领退料包装数量
            mocte.setTE021(new BigDecimal(0.00));
            // 包装单位
            mocte.setTE022("");
            // 设置批号设置 说明
            mocte.setTE023("");
            // 设置折算率
            mocte.setTE024(new BigDecimal(0.00));
            // 设置库位
            // 获取库位信息

            mocte.setTE025("##########");
            // 设置库存单位
//            INVMB invmb = invmbMapper.selectOne(new QueryWrapper<Invmb>().eq("MB001",lllist.getWlbh()));
            INVMB invmb = invmbMapper.getINVMBByMB001(lllist.getWlbh());

            mocte.setTE026(invmb.getMB004().trim());

            // 设置领料库存数量
            mocte.setTE027(mocte.getTE005());

            mocte.setUDF01(invmb.getUDF01());

            // 设置 类型 1.工程品号 2.正式品号[DEF:"2"]
            mocte.setTEC01("2");
            // 设置 核建确认  Y/N[DEF:"N"]
            mocte.setTEH01("N");
            moctes.add(mocte);
            if (flag) {
                moctds.add(moctd);
            }
            log.info(mocte.toString());

        }

        if (errorMsg != null)
            return Result.error(errorMsg);

        // 设置领料单的领料单头  数量
        moctc.setTC029(new BigDecimal(count));
        moctc.setUDF01(lldDto.getUDF01());

        // 添加 单头单身
        /*moctcMapper.insert(moctc);
        for (MOCTE mocte : moctes) {
            mocteMapper.insert(mocte);
        }*/
        moctcMapper.add(moctc);
        for (MOCTE mocte : moctes) {
            mocteMapper.add(mocte);
        }
        for (Moctd moctd : moctds) {
            moctdMapper.insert(moctd);
        }


        // 判断审核源是否打开
        ShenHe shenHe = new ShenHe();
        //shenHe.setCom(moctc.getCompany());
        shenHe.setCom("ttc");
        shenHe.setProgram("MOCI03");
        shenHe.setDb(lld);
        shenHe.setDh(moctc.getTC002());
        shenHe.setRq(nowTime.substring(0,8));
        shenHe.setType("DO");
        shenHe.setUser(creator);


        String url = "http://" + RunHttp.getIp() + ":9000/api/yifei/audit";
//        String url = "http://" + "36.134.50.98" + ":9000/api/yifei/audit";

        String jsonString = JSON.toJSONString(shenHe);


        String ans = null;

        try {
            System.out.println("11111");
            System.out.println(url);
            System.out.println(jsonString);
            ans = HttpClientUtil.postRequest(url, jsonString);
            System.out.println("22222");

        }catch (IOException e){
            /*moctcMapper.delete(new QueryWrapper<Moctc>().eq("TC001",lld).eq("TC002",tc002));
            mocteMapper.delete(new QueryWrapper<Mocte>().eq("TE001",lld).eq("TE002",tc002));*/
            moctcMapper.delete(lld,tc002);
            mocteMapper.delete(lld,tc002);
            moctdMapper.delete(new QueryWrapper<Moctd>().eq("TD001",lld).eq("TD002",tc002));

            //System.out.println("出现异常请查看审批后台是否开启");
            log.info("出现异常请查看审批后台是否开启");
            System.out.println(e);
            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return Result.error("出现异常请查看审批后台是否开启！");
        }
        HttpResult httpResult =  new HttpResult();
        if (ans == null){
            /*moctcMapper.delete(new QueryWrapper<Moctc>().eq("TC001",lld).eq("TC002",tc002));
            mocteMapper.delete(new QueryWrapper<Mocte>().eq("TE001",lld).eq("TE002",tc002));*/
            moctcMapper.delete(lld,tc002);
            mocteMapper.delete(lld,tc002);
            moctdMapper.delete(new QueryWrapper<Moctd>().eq("TD001",lld).eq("TD002",tc002));

            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return Result.error("出现异常请查看审批后台是否开启");
        }
        else {
            System.out.println(ans);
            ans = ans.replace("\\r","");
            System.out.println("ans :"  + ans);
            httpResult = JSON.parseObject(ans,HttpResult.class);
            System.out.println("httpResult: " + httpResult);
            //System.out.println(httpResult.toString());
        }
        if (httpResult.getStatus().equals("失败")){
            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            /*moctcMapper.delete(new QueryWrapper<Moctc>().eq("TC001",lld).eq("TC002",tc002));
            mocteMapper.delete(new QueryWrapper<Mocte>().eq("TE001",lld).eq("TE002",tc002));*/
            moctcMapper.delete(lld,tc002);
            mocteMapper.delete(lld,tc002);
            moctdMapper.delete(new QueryWrapper<Moctd>().eq("TD001",lld).eq("TD002",tc002));
            return Result.error("审核失败！\\n" + "原因：" + httpResult.getReason() + "\\n 详情：" + httpResult.getDetail());
        }
        //String dhdh = ;
        Result result =  Result.success();
        result.setMsg(lld + "-" + tc002);
        return result;
    }



    @Override
    public Result supplement(LldDto lldDto)  {




        int flage = 0;


        // 领料单创建人
        String creator = lldDto.getCreator();
        // 领料日期
        String rq = lldDto.getRq();
        // 工厂编号
        String gcbh = lldDto.getGcbh();
        //  工作中心
        String gzzx = lldDto.getGzzx();
        //  领料单单别
        String lld = lldDto.getDb();
        // 领料工单列表
        List<LldList> list = lldDto.getList();

        // 1.判断领料单是否合规

        // 2.判断工单是否合规
        String errorMsg =  null ;
        for (LldList lllist : list) {

            String db = lllist.getGddb();
            String dh = lllist.getGddh();
            /*QueryWrapper<Cmsmq> cmsmqQueryWrapper = new QueryWrapper<>();
            cmsmqQueryWrapper.eq("MQ001",db);
            CMSMQ cmsmq = cmsmqMapper.selectOne(cmsmqQueryWrapper);*/
            CMSMQ cmsmq = cmsmqMapper.findByMQ001(db);
            //String mq001 = cmsmqMapper.isExitByMQ001(db);
            //if (mq001 == null || )
            //System.out.println("mq001::" + mq001);
            if (!(db.substring(0,2).equals("51")||db.substring(0,2).equals("52"))||cmsmq==null)
            {
                //log.info(cmsmqMapper.isExitByMQ001(db));

                System.out.println("---工单单别为：" + db);
                if (errorMsg != null)
                    errorMsg  += "\n" + db +" : 这个工单单别有误！";
                else
                    errorMsg  =  db +" : 这个工单单别有误！";
                flage = 1;
                continue;
            }
            if (errorMsg != null && flage ==1) continue;

            // 获取工单信息
            /*QueryWrapper<Mocta> moctaQueryWrapper = new QueryWrapper<>();
            moctaQueryWrapper.eq("TA001",db)
                    .eq("TA002",dh);

            MOCTA mocta = moctaMapper.selectOne(moctaQueryWrapper);*/
            MOCTA mocta = moctaMapper.findByDbWithDh(db,dh);

            if (mocta==null){
                if (errorMsg != null)
                    errorMsg  += "\n" + dh +" : 这个工单单号不存在！";
                else
                    errorMsg  =  dh +" :  这个工单单号不存在！";
                flage = 2;
                continue;
            }
            if (errorMsg != null && flage==2) continue;
            // 判断工单是否被审核
            if (!mocta.getTA013().equals("Y")){
                if (errorMsg != null)
                    errorMsg  += "\n" + dh +" : 这个工单单号没有审核！";
                else
                    errorMsg  =  dh +" :  这个工单单号没有审核！";
                continue;
            }

            log.info(mocta.toString());
        }
        System.out.println("123");
        if (errorMsg != null) {
            System.out.println(errorMsg);
            /*Result result = new Result();
            result.setMsg(errorMsg);
            result.setCode("404");
            return result;*/
            return Result.error(errorMsg);
        }

        // 3.领料单单身信息创建
        MOCTC moctc = new MOCTC();
        String nowTime = TimeUtils.getNowTime();
        // 设置创建者
        moctc.setCOMPANY("ttc");
        moctc.setCREATOR(creator);

        //ADMMF admmf = admmfMapper.selectOne(new QueryWrapper<Admmf>().eq("MF001", creator));
        ADMMF admmf = admmfMapper.selectByMF001(creator);
        System.out.println("admmf:" + admmf.toString());
        moctc.setUSR_GROUP(admmf.getMF004());
        moctc.setCREATE_DATE(nowTime);
        moctc.setMODI_DATE("");
        moctc.setMODIFIER("");
        moctc.setFLAG(new BigDecimal(2));

        // 获取领料单单别 对应的信息
        //CMSMQ cmsmq = cmsmqMapper.selectOne(new QueryWrapper<Cmsmq>().eq("MQ001",lld));
        CMSMQ cmsmq = cmsmqMapper.findByMQ001(lld);

        // 领料单对应的年位数
        int yearLength = cmsmq.getMQ005().intValue();
        // 获取根据单别获取单号
        String tc002 = null;
        if (yearLength == 4) tc002 = moctcMapper.getNewTC002Year4(lld);
        else tc002 = moctcMapper.getNewTC002Year2(lld);

        moctc.setTC001(lld);
        moctc.setTC002(tc002);
        moctc.setTC003(rq);
        moctc.setTC004(gcbh);
        moctc.setTC005(gzzx);
        moctc.setTC006("");
        moctc.setTC007("");
        moctc.setTC008(lld.substring(0,2));
        // 设置审核码
        moctc.setTC009("N");
        // 设置打印次数
        moctc.setTC010(new BigDecimal(0));
        // 设置生成分录-成本  Y/N
        moctc.setTC011("N");
        // 设置 生成排序 1.按工单单号、2.按材料品号
        moctc.setTC012("1");
        // 取数方式 Y.需领用量、N.与库存量比较
        moctc.setTC013("Y");
        // 设置  单据日期 过来的
        moctc.setTC014(rq);
        // 设置审核者
        moctc.setTC015("");
        // 签核状态码 0.待处理、S.传送中、1.签核中、2.退件、3.已核准、4.撤销审核中、5.作废中、
        // 6.取消作废中、N.不运行电子签核[DEF:"N"]
        moctc.setTC016("N");
        // 设置 传送次数
        moctc.setTC017(new BigDecimal(0));
        //   来源别 0.自行输入、1.工单、2.生产入库自动扣料、3.委外进自动扣料、4.委外退自动扣料、
        // 5.开工单、6.委外进厂供料自动扣料、7.委外退厂供料自动扣料 8.批次发料自动退料[DEF:"0"]
        moctc.setTC018("0");
        // 设置   来源单别
        //moctc.setTC019(db);
        // 设置 来源单号
        //moctc.setTC020(dh);
        //moctcMapper.add(moctc);
        // 设置 部门
        // 根据工作中心编号获取 工作中心
        //CMSMD cmsmd = cmsmdMapper.selectOne(new QueryWrapper<Cmsmd>().eq("MD001",gzzx));
        CMSMD cmsmd = cmsmdMapper.getCMSMDByMD001(gzzx);
        moctc.setTC021(cmsmd.getMD015().trim());
        // 设置人员编号
        moctc.setTC028("");
        moctc.setTC031("");
        log.info("moctc :" + moctc.toString());

        //添加领料单单身

        List<MOCTE> moctes = new ArrayList<>();
        int xh = 1;
        double count = 0;
        for (LldList lllist : list) {
            // 判断该物料是否领取完成

            //   判断是否存在该物料
            /*MOCTB moctb = moctbMapper.selectOne(new QueryWrapper<Moctb>().eq("TB001", lllist.getGddb())
                    .eq("TB002", lllist.getGddh()).
                    eq("TB003", lllist.getWlbh()));*/

            MOCTB moctb = moctbMapper.getMOCTBBYTB001andTB002andTB003(lllist.getGddb(), lllist.getGddh(),lllist.getWlbh());
            if (moctb == null) {
                if (errorMsg == null )
                    errorMsg = "工单单别为: " + lllist.getGddb() +"，  工单单号为"+ lllist.getGddh() + "的工单中, 没有物料编号为：" + lllist.getWlbh() +  "物料信息";
                else errorMsg = "\n" + errorMsg;

                continue;
            }

            // 存在查看库存数量和要领的数量 需要获取工单单身每个物料的仓库
            //物料对应的仓库编号
            String tb009 = moctb.getTB009();
           /* QueryWrapper<Invmc> invmcQueryWrapper = new QueryWrapper<>();
            invmcQueryWrapper.eq("MC001",lllist.getWlbh()).eq("MC002",tb009);
            INVMC invmc = invmcMapper.selectOne(invmcQueryWrapper);*/

            INVMC invmc = invmcMapper.getINVMCByMC001WithMC002(lllist.getWlbh(),tb009);


            // 获取库存数量
            Double mc007 = invmc.getMC007().doubleValue();
            if (mc007 < lllist.getQtw()){
                if (errorMsg != null)
                    errorMsg  +=
                            "/n" + "工单单别为 ：" + lllist.getGddb() + "，单号为：" + lllist.getGddh() + "，中的需要领料的单号为：" + lllist.getWlbh() +"，的产品在仓库中的数量不足!" ;
                else
                    errorMsg  =
                            "工单单别为 ：" + lllist.getGddb() + "，单号为：" + lllist.getGddh() + "，中的需要领料的单号为：" + lllist.getWlbh() +"，的产品在仓库中的数量不足!" ;

                log.info(errorMsg);
                flage =3;
                continue;
            }

            // errorMsg 不为空说明 存在库问题 不用在列表中添加
            if (errorMsg != null && flage == 3)
                continue;

            // 仓库库存满足  设置领料单单身
            count += lllist.getQtw();
            MOCTE mocte = new MOCTE();
            mocte.setCOMPANY(moctb.getCOMPANY().trim());
            mocte.setCREATOR(creator);
            mocte.setUSR_GROUP(admmf.getMF004());
            mocte.setCREATE_DATE(nowTime);
            mocte.setFLAG(new BigDecimal(2));
            mocte.setTE001(lld);
            mocte.setTE002(tc002);
            mocte.setTE003(String.format("%04d", xh));
            xh++;
            // 物料品号
            mocte.setTE004(lllist.getWlbh());
            // 领料数量
            mocte.setTE005(new BigDecimal(lllist.getQtw()));
            // 单位
            mocte.setTE006(moctb.getTB007().trim());
            // 参考单位
            mocte.setTE007("");
            // 仓库
            mocte.setTE008(tb009);
            // 工艺
            mocte.setTE009("****");
            //批号
            mocte.setTE010("********************");
            // 工单单别 单号
            mocte.setTE011(lllist.getGddb());
            mocte.setTE012(lllist.getGddh());
            // 设置领料说明
            mocte.setTE013("可用量: " + Math.round(mc007));
            // 备注
            mocte.setTE014("");
            mocte.setTE015("");
            // 材料类型
            mocte.setTE016(moctb.getTB011());

            mocte.setTE017(moctb.getTB012().trim());
            // 设置材料规格
            mocte.setTE018(moctb.getTB013().trim());
            // 设置审核码
            mocte.setTE019("N");
            // 设置项目编号
            //mocte.setTE020(moctb.getTB038().trim());
            //mocte.setTE020("********************");
            mocte.setTE020("");
            // 设置领退料包装数量
            mocte.setTE021(new BigDecimal(0.00));
            // 包装单位
            mocte.setTE022("");
            // 设置批号设置 说明
            mocte.setTE023("");
            // 设置折算率
            mocte.setTE024(new BigDecimal(0.00));
            // 设置库位
            // 获取库位信息

            mocte.setTE025("##########");
            // 设置库存单位
//            INVMB invmb = invmbMapper.selectOne(new QueryWrapper<Invmb>().eq("MB001",lllist.getWlbh()));
            INVMB invmb = invmbMapper.getINVMBByMB001(lllist.getWlbh());
            mocte.setTE026(invmb.getMB004().trim());

            // 设置领料库存数量
            mocte.setTE027(mocte.getTE005());

            mocte.setUDF01(invmb.getUDF01());

            // 设置 类型 1.工程品号 2.正式品号[DEF:"2"]
            mocte.setTEC01("2");
            // 设置 核建确认  Y/N[DEF:"N"]
            mocte.setTEH01("N");
            moctes.add(mocte);
            log.info(mocte.toString());

        }

        if (errorMsg != null)
            return Result.error(errorMsg);

        // 设置领料单的领料单头  数量
        moctc.setTC029(new BigDecimal(count));


        // 添加 单头单身
        /*moctcMapper.insert(moctc);
        for (MOCTE mocte : moctes) {
            mocteMapper.insert(mocte);
        }*/
        moctcMapper.add(moctc);
        for (MOCTE mocte : moctes) {
            mocteMapper.add(mocte);
        }


        // 判断审核源是否打开
        ShenHe shenHe = new ShenHe();
        //shenHe.setCom(moctc.getCompany());
        shenHe.setCom("ttc");
        shenHe.setProgram("MOCI03");
        shenHe.setDb(lld);
        shenHe.setDh(moctc.getTC002());
        shenHe.setRq(nowTime.substring(0,8));
        shenHe.setType("DO");
        shenHe.setUser(creator);

        String url = "http://" + RunHttp.getIp() + ":9000/api/yifei/audit";
//        String url = "http://" + "192.168.1.47" + ":9000/api/yifei/audit";

        String jsonString = JSON.toJSONString(shenHe);


        String ans = null;

        try {
            System.out.println("11111");
            System.out.println(url);
            System.out.println(jsonString);
            ans = HttpClientUtil.postRequest(url, jsonString);
            System.out.println("22222");

        }catch (IOException e){
            /*moctcMapper.delete(new QueryWrapper<Moctc>().eq("TC001",lld).eq("TC002",tc002));
            mocteMapper.delete(new QueryWrapper<Mocte>().eq("TE001",lld).eq("TE002",tc002));*/
            moctcMapper.delete(lld,tc002);
            mocteMapper.delete(lld,tc002);
            //System.out.println("出现异常请查看审批后台是否开启");
            log.info("出现异常请查看审批后台是否开启");
            System.out.println(e);
            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return Result.error("出现异常请查看审批后台是否开启！");
        }
        HttpResult httpResult =  new HttpResult();
        if (ans == null){
            /*moctcMapper.delete(new QueryWrapper<Moctc>().eq("TC001",lld).eq("TC002",tc002));
            mocteMapper.delete(new QueryWrapper<Mocte>().eq("TE001",lld).eq("TE002",tc002));*/
            moctcMapper.delete(lld,tc002);
            mocteMapper.delete(lld,tc002);
            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return Result.error("出现异常请查看审批后台是否开启");
        }
        else {
            System.out.println(ans);
            ans = ans.replace("\\r","");
            System.out.println("ans :"  + ans);
            httpResult = JSON.parseObject(ans,HttpResult.class);
            System.out.println("httpResult: " + httpResult);
            //System.out.println(httpResult.toString());
        }
        if (httpResult.getStatus().equals("失败")){
            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            /*moctcMapper.delete(new QueryWrapper<Moctc>().eq("TC001",lld).eq("TC002",tc002));
            mocteMapper.delete(new QueryWrapper<Mocte>().eq("TE001",lld).eq("TE002",tc002));*/
            moctcMapper.delete(lld,tc002);
            mocteMapper.delete(lld,tc002);
            return Result.error("审核失败！\\n" + "原因：" + httpResult.getReason() + "\\n 详情：" + httpResult.getDetail());
        }
        //String dhdh = ;
        Result result =  Result.success();
        result.setMsg(lld + "-" + tc002);
        return result;
    }

    @Override
    public Result refund(LldDto lldDto){

        int flage = 0;


        // 领料单创建人
        String creator = lldDto.getCreator();
        // 领料日期
        String rq = lldDto.getRq();
        // 工厂编号
        String gcbh = lldDto.getGcbh();
        //  工作中心
        String gzzx = lldDto.getGzzx();
        //  退料单单别
        String lld = lldDto.getDb();
        // 退料工单列表
        List<LldList> list = lldDto.getList();

        // 1.判断领料单是否合规

        // 2.判断工单是否合规
        String errorMsg =  null ;
        for (LldList lllist : list) {

            String db = lllist.getGddb();
            String dh = lllist.getGddh();
            /*QueryWrapper<Cmsmq> cmsmqQueryWrapper = new QueryWrapper<>();
            cmsmqQueryWrapper.eq("MQ001",db);
            CMSMQ cmsmq = cmsmqMapper.selectOne(cmsmqQueryWrapper);*/
            CMSMQ cmsmq = cmsmqMapper.findByMQ001(db);
            //String mq001 = cmsmqMapper.isExitByMQ001(db);
            //if (mq001 == null || )
            //System.out.println("mq001::" + mq001);
            if (!(db.substring(0,2).equals("51")||db.substring(0,2).equals("52"))||cmsmq==null)
            {
                //log.info(cmsmqMapper.isExitByMQ001(db));

                System.out.println("---工单单别为：" + db);
                if (errorMsg != null)
                    errorMsg  += "\n" + db +" : 这个工单单别有误！";
                else
                    errorMsg  =  db +" : 这个工单单别有误！";
                flage = 1;
                continue;
            }
            if (errorMsg != null && flage ==1) continue;

            // 获取工单信息
            /*QueryWrapper<Mocta> moctaQueryWrapper = new QueryWrapper<>();
            moctaQueryWrapper.eq("TA001",db)
                    .eq("TA002",dh);

            MOCTA mocta = moctaMapper.selectOne(moctaQueryWrapper);*/
            MOCTA mocta = moctaMapper.findByDbWithDh(db,dh);

            if (mocta==null){
                if (errorMsg != null)
                    errorMsg  += "\n" + dh +" : 这个工单单号不存在！";
                else
                    errorMsg  =  dh +" :  这个工单单号不存在！";
                flage = 2;
                continue;
            }
            if (errorMsg != null && flage==2) continue;
            // 判断工单是否被审核
            if (!mocta.getTA013().equals("Y")){
                if (errorMsg != null)
                    errorMsg  += "\n" + dh +" : 这个工单单号没有审核！";
                else
                    errorMsg  =  dh +" :  这个工单单号没有审核！";
                continue;
            }

            log.info(mocta.toString());
        }
        System.out.println("123");
        if (errorMsg != null) {
            System.out.println(errorMsg);
            /*Result result = new Result();
            result.setMsg(errorMsg);
            result.setCode("404");
            return result;*/
            return Result.error(errorMsg);
        }

        // 3.退料单单头信息创建
        MOCTC moctc = new MOCTC();
        String nowTime = TimeUtils.getNowTime();
        // 设置创建者
        moctc.setCOMPANY("ttc");
        moctc.setCREATOR(creator);

        //ADMMF admmf = admmfMapper.selectOne(new QueryWrapper<Admmf>().eq("MF001", creator));
        ADMMF admmf = admmfMapper.selectByMF001(creator);
        System.out.println("admmf:" + admmf.toString());
        moctc.setUSR_GROUP(admmf.getMF004());
        moctc.setCREATE_DATE(nowTime);
        moctc.setMODI_DATE("");
        moctc.setMODIFIER("");
        moctc.setFLAG(new BigDecimal(2.0));

        // 获取领料单单别 对应的信息
        //CMSMQ cmsmq = cmsmqMapper.selectOne(new QueryWrapper<Cmsmq>().eq("MQ001",lld));
        CMSMQ cmsmq = cmsmqMapper.findByMQ001(lld);

        // 领料单对应的年位数
        int yearLength = cmsmq.getMQ005().intValue();
        // 获取根据单别获取单号
        String tc002 = null;
        if (yearLength == 4) tc002 = moctcMapper.getNewTC002Year4(lld);
        else tc002 = moctcMapper.getNewTC002Year2(lld);

        moctc.setTC001(lld);
        moctc.setTC002(tc002);
        moctc.setTC003(rq);
        moctc.setTC004(gcbh);
        moctc.setTC005(gzzx);
        moctc.setTC006("");
        moctc.setTC007("");
        moctc.setTC008(lld.substring(0,2));
        // 设置审核码
        moctc.setTC009("N");
        // 设置打印次数
        moctc.setTC010(new BigDecimal(0));
        // 设置生成分录-C本  Y/N
        moctc.setTC011("N");
        // 设置 生成排序C1.按工单单号、2.按材料品号
        moctc.setTC012("1");
        // 取数方式 Y.C领用量、N.与库存量比较
        moctc.setTC013("Y");
        // 设置  单据日C 过来的
        moctc.setTC014(rq);
        // 设置审核者
        moctc.setTC015("");
        // 签核状态码 0C待处理、S.传送中、1.签核中、2.退件、3.已核准、4.撤销审核中、5.作废中、
        // 6.取消作废中CN.不运行电子签核[DEF:"N"]
        moctc.setTC016("N");
        // 设置 传送次数
        moctc.setTC017(new BigDecimal(0));
        //   来源别 0.自行输入、1.工单、2.生产入库自动扣料、3.委外进自动扣料、4.委外退自动扣料、
        // 5.开工单、6.委外进厂供料自动扣料、7.委外退厂供料自动扣料 8.批次发料自动退料[DEF:"0"]
        moctc.setTC018("0");
        // 设置   来源单别
        //moctc.setTC019(db);
        // 设置 来源单号
        //moctc.setTC020(dh);
        //moctcMapper.add(moctc);
        // 设置 部门
        // 根据工作中心编号获取 工作中心
        //CMSMD cmsmd = cmsmdMapper.selectOne(new QueryWrapper<Cmsmd>().eq("MD001",gzzx));
        CMSMD cmsmd = cmsmdMapper.getCMSMDByMD001(gzzx);
        moctc.setTC021(cmsmd.getMD015().trim());
        // 设置人员编号C
        moctc.setTC028("");
        moctc.setTC031("");
        log.info("moctc :" + moctc.toString());

        //添加领料单单身

        List<MOCTE> moctes = new ArrayList<>();
        int xh = 1;
        double count = 0;
        for (LldList lllist : list) {
            // 判断该物料是否领取完成

            //   判断是否存在该物料
            /*MOCTB moctb = moctbMapper.selectOne(new QueryWrapper<Moctb>().eq("TB001", lllist.getGddb())
                    .eq("TB002", lllist.getGddh()).
                    eq("TB003", lllist.getWlbh()));*/
            MOCTB moctb = moctbMapper.getMOCTBBYTB001andTB002andTB003(lllist.getGddb(), lllist.getGddh(),lllist.getWlbh());
            if (moctb == null) {
                if (errorMsg == null )
                    errorMsg = "工单单别为: " + lllist.getGddb() +"，  工单单号为"+ lllist.getGddh() + "的工单中, 没有物料编号为：" + lllist.getWlbh() +  "物料信息";
                else errorMsg = "\n" + errorMsg;

                continue;
            }

            // 存在查看库存数量和要领的数量 需要获取工单单身每个物料的仓库
            //物料对应的仓库编号
            String tb009 = moctb.getTB009();
            /*QueryWrapper<Invmc> invmcQueryWrapper = new QueryWrapper<>();
            invmcQueryWrapper.eq("MC001",lllist.getWlbh()).eq("MC002",tb009);
            Invmc invmc = invmcMapper.selectOne(invmcQueryWrapper);*/
            INVMC invmc = invmcMapper.getINVMCByMC001WithMC002(lllist.getWlbh(),tb009);

            Double mc007 = invmc.getMC007().doubleValue();
            /*
            // 获取库存数量

            if (mc007 < lllist.getQtw()){
                if (errorMsg != null)
                    errorMsg  +=
                            "/n" + "工单单别为 ：" + lllist.getGddb() + "，单号为：" + lllist.getGddh() + "，中的需要领料的单号为：" + lllist.getWlbh() +"，的产品在仓库中的数量不足!" ;
                else
                    errorMsg  =
                            "工单单别为 ：" + lllist.getGddb() + "，单号为：" + lllist.getGddh() + "，中的需要领料的单号为：" + lllist.getWlbh() +"，的产品在仓库中的数量不足!" ;

                log.info(errorMsg);
                flage =3;
                continue;
            }

            // errorMsg 不为空说明 存在库问题 不用在列表中添加
            if (errorMsg != null && flage == 3)
                continue;

             */

            // 仓库库存满足  设置领料单单身
            count += lllist.getQtw();
            MOCTE mocte = new MOCTE();
            mocte.setCOMPANY(moctb.getCOMPANY().trim());
            mocte.setCREATOR(creator);
            mocte.setUSR_GROUP(admmf.getMF004());
            mocte.setCREATE_DATE(nowTime);
            mocte.setFLAG(new BigDecimal(2));
            mocte.setTE001(lld);
            mocte.setTE002(tc002);
            mocte.setTE003(String.format("%04d", xh));
            xh++;
            // 物料品E
            mocte.setTE004(lllist.getWlbh());
            // 领料数E
            mocte.setTE005(new BigDecimal(lllist.getQtw()));
            // 单E
            mocte.setTE006(moctb.getTB007().trim());
            // 参考单E
            mocte.setTE007("");
            // 仓E
            mocte.setTE008(tb009);
            // 工E
            mocte.setTE009("****");
            //批E
            mocte.setTE010("********************");
            // 工单单别 单E
            mocte.setTE011(lllist.getGddb());
            mocte.setTE012(lllist.getGddh());
            // 设置领料说E
            mocte.setTE013("可用量: " + Math.round(mc007));
            // 备E
            mocte.setTE014("");
            mocte.setTE015("");
            // 材料类E
            mocte.setTE016(moctb.getTB011());
            mocte.setTE017(moctb.getTB012().trim());
            // 设置材料规E
            mocte.setTE018(moctb.getTB013().trim());
            // 设置审核E
            mocte.setTE019("N");
            // 设置项目编E
            //mocte.seETE020(moctb.getTB038().trim());
            //mocte.seETE020("********************");
            mocte.setTE020("");
            // 设置领退料包装E量
            mocte.setTE021(new BigDecimal(0.00));
            // 包装单E
            mocte.setTE022("");
            // 设置批号设置 E明
            mocte.setTE023("");
            // 设置折算E
            mocte.setTE024(new BigDecimal(0.00));
            // 设置库E
            // 获取库位信E
            mocte.setTE025("##########");
            // 设置库存单位
//            INVMB invmb = invmbMapper.selectOne(new QueryWrapper<Invmb>().eq("MB001",lllist.getWlbh()));
            INVMB invmb = invmbMapper.getINVMBByMB001(lllist.getWlbh());
            mocte.setTE026(invmb.getMB004().trim());

            // 设置领料库存数量
            mocte.setTE027(mocte.getTE005());

            mocte.setUDF01(invmb.getUDF01());

            // 设置 类型 1.工程品号 2.正式品号[DEF:"2"]
            mocte.setTEC01("2");
            // 设置 核建确认  Y/N[DEF:"N"]
            mocte.setTEH01("N");
            moctes.add(mocte);
            log.info(mocte.toString());

        }

        if (errorMsg != null)
            return Result.error(errorMsg);

        // 设置领料单的领料单头  数量
        moctc.setTC029(new BigDecimal(count));


        // 添加 单头单身
        /*moctcMapper.insert(moctc);
        for (MOCTE mocte : moctes) {
            mocteMapper.insert(mocte);
        }*/
        moctcMapper.add(moctc);
        for (MOCTE mocte : moctes) {
            mocteMapper.add(mocte);
        }


        // 判断审核源是否打开
        ShenHe shenHe = new ShenHe();
        //shenHe.setCom(moctc.getCompany());
        shenHe.setCom("ttc");
        shenHe.setProgram("MOCI04");
        shenHe.setDb(lld);
        shenHe.setDh(moctc.getTC002());
        shenHe.setRq(nowTime.substring(0,8));
        shenHe.setType("DO");
        shenHe.setUser(creator);

        String url = "http://" + RunHttp.getIp() + ":9000/api/yifei/audit";
//        String url = "http://" + "192.168.1.47" + ":9000/api/yifei/audit";

        String jsonString = JSON.toJSONString(shenHe);


        String ans = null;

        try {
            System.out.println("11111");
            System.out.println(url);
            System.out.println(jsonString);
            ans = HttpClientUtil.postRequest(url, jsonString);
            System.out.println("22222");

        }catch (IOException e){
            /*moctcMapper.delete(new QueryWrapper<Moctc>().eq("TC001",lld).eq("TC002",tc002));
            mocteMapper.delete(new QueryWrapper<Mocte>().eq("TE001",lld).eq("TE002",tc002));*/
            moctcMapper.delete(lld,tc002);
            mocteMapper.delete(lld,tc002);
            //System.out.println("出现异常请查看审批后台是否开启");
            log.info("出现异常请查看审批后台是否开启");
            System.out.println(e);
            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return Result.error("出现异常请查看审批后台是否开启！");
        }
        HttpResult httpResult =  new HttpResult();
        if (ans == null){
            /*moctcMapper.delete(new QueryWrapper<Moctc>().eq("TC001",lld).eq("TC002",tc002));
            mocteMapper.delete(new QueryWrapper<Mocte>().eq("TE001",lld).eq("TE002",tc002));*/
            moctcMapper.delete(lld,tc002);
            mocteMapper.delete(lld,tc002);
            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return Result.error("出现异常请查看审批后台是否开启");
        }
        else {
            System.out.println(ans);
            ans = ans.replace("\\r","");
            System.out.println("ans :"  + ans);
            httpResult = JSON.parseObject(ans,HttpResult.class);
            System.out.println("httpResult: " + httpResult);
            //System.out.println(httpResult.toString());
        }
        if (httpResult.getStatus().equals("失败")){
            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            /*moctcMapper.delete(new QueryWrapper<Moctc>().eq("TC001",lld).eq("TC002",tc002));
            mocteMapper.delete(new QueryWrapper<Mocte>().eq("TE001",lld).eq("TE002",tc002));*/
            moctcMapper.delete(lld,tc002);
            mocteMapper.delete(lld,tc002);
            return Result.error("审核失败！\\n" + "原因：" + httpResult.getReason() + "\\n 详情：" + httpResult.getDetail());
        }
        //String dhdh = ;
        Result result =  Result.success();
        result.setMsg(lld + "-" + tc002);
        return result;
    }

    @Override
    public Result revokeLld(String creator , String db, String dh) {
        String nowTime = TimeUtils.getNowTime();
        // 判断审核源是否打开
        ShenHe shenHe = new ShenHe();
        //shenHe.setCom(moctc.getCompany());
        shenHe.setCom("ttc");
        shenHe.setProgram("MOCI03");
        shenHe.setDb(db);
        shenHe.setDh(dh);
        shenHe.setRq(nowTime.substring(0,8));
        shenHe.setType("UNDO");
        shenHe.setUser(creator);

        String url = "http://" + RunHttp.getIp() + ":9000/api/yifei/audit";
//        String url = "http://" + "192.168.1.47" + ":9000/api/yifei/audit";

        String jsonString = JSON.toJSONString(shenHe);

        String ans = null;
        try {
            System.out.println(url);
            System.out.println(jsonString);
            ans = HttpClientUtil.postRequest(url, jsonString);
        }catch (IOException e){
            //System.out.println("出现异常请查看审批后台是否开启");
            log.info("出现异常请查看审批后台是否开启");
            System.out.println(e);
            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return Result.error("出现异常请查看审批后台是否开启！");
        }
        HttpResult httpResult =  new HttpResult();
        if (ans == null){
            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return Result.error("出现异常请查看审批后台是否开启");
        }
        else {
            System.out.println(ans);
            ans = ans.replace("\\r","");
            System.out.println("ans :"  + ans);
            httpResult = JSON.parseObject(ans,HttpResult.class);
            System.out.println("httpResult: " + httpResult);
            //System.out.println(httpResult.toString());
        }
        if (httpResult.getStatus().equals("失败")){
            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return Result.error("审核失败！\\n" + "原因：" + httpResult.getReason() + "\\n 详情：" + httpResult.getDetail());
        }
        mocteMapper.delete(db, dh);
        moctcMapper.delete(db, dh);
        return Result.success();
    }

    @Override
    public Result revokeRefund(String creator, String db, String dh) {
        String nowTime = TimeUtils.getNowTime();
        // 判断审核源是否打开
        ShenHe shenHe = new ShenHe();
        //shenHe.setCom(moctc.getCompany());
        shenHe.setCom("ttc");
        shenHe.setProgram("MOCI04");
        shenHe.setDb(db);
        shenHe.setDh(dh);
        shenHe.setRq(nowTime.substring(0,8));
        shenHe.setType("UNDO");
        shenHe.setUser(creator);

        String url = "http://" + RunHttp.getIp() + ":9000/api/yifei/audit";
//        String url = "http://" + "192.168.1.47" + ":9000/api/yifei/audit";

        String jsonString = JSON.toJSONString(shenHe);


        String ans = null;

        try {
            System.out.println("11111");
            System.out.println(url);
            System.out.println(jsonString);
            ans = HttpClientUtil.postRequest(url, jsonString);
            System.out.println("22222");

        }catch (IOException e){
            //System.out.println("出现异常请查看审批后台是否开启");
            log.info("出现异常请查看审批后台是否开启");
            System.out.println(e);
            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return Result.error("出现异常请查看审批后台是否开启！");
        }
        HttpResult httpResult =  new HttpResult();
        if (ans == null){
            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return Result.error("出现异常请查看审批后台是否开启");
        }
        else {
            System.out.println(ans);
            ans = ans.replace("\\r","");
            System.out.println("ans :"  + ans);
            httpResult = JSON.parseObject(ans, HttpResult.class);
            System.out.println("httpResult: " + httpResult);
            //System.out.println(httpResult.toString());
        }
        if (httpResult.getStatus().equals("失败")){
            //TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return Result.error("审核失败！\\n" + "原因：" + httpResult.getReason() + "\\n 详情：" + httpResult.getDetail());
        }


        return Result.success();
    }
}
